package com.xwh.article.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xwh.article.controller.dto.SoftwareDto;
import com.xwh.article.controller.param.SoftwareParam;
import com.xwh.article.entity.Software;
import com.xwh.article.mapper.SoftwareMapper;
import com.xwh.article.service.SoftwareService;
import com.xwh.core.dao.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author xwh
 **/

@Service
@RequiredArgsConstructor
public class SoftwareServiceImpl extends ServiceImpl<SoftwareMapper, Software> implements SoftwareService {

    final SoftwareMapper softwareMapper;

    @Override
    public void add(SoftwareDto software) {
        // 软件名不能重复
        QueryWrapper<Software> query = new QueryWrapper<>();
        query.eq("software_name", software.getSoftwareName());
        if (list(query).size() > 0) {
            throw new RuntimeException("软件名不能重复");
        }
        Software software1 = BeanUtil.copyProperties(software, Software.class);
        save(software1);
    }

    @Override
    public Page<Software> pageList(SoftwareParam softwareParam) {
        return softwareMapper.pageList(softwareParam);
    }

}
